package com.tom.controller;

import com.tom.model.req.AnalysisSqlReq;
import com.tom.model.req.ExecuteSqlReq;
import com.tom.adapter.AnalysisSqlService;
import com.tom.utils.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 解析SQL
 *
 * @author zx
 * @date 2024-11-09 18:00
 */
@RestController
@RequestMapping("/analysis/sql")
public class AnalysisSqlController {

    @Autowired
    private AnalysisSqlService analysisSqlService;

    @PostMapping("/")
    public BaseResponse<String> analysisSql(@RequestBody AnalysisSqlReq analysisSqlReq){
        String sql = analysisSqlService.analysisSql(analysisSqlReq);
        return BaseResponse.success(sql);
    }

    @PostMapping("/executeSql")
    public BaseResponse<List<Map<String,Object>>> executeSql(@RequestBody ExecuteSqlReq executeSqlReq){
        List<Map<String,Object>> resultListMap = analysisSqlService.executeSql(executeSqlReq);
        return BaseResponse.success(resultListMap);
    }
}
